<?php

/*
	info: 找回密码
*/

require '../common.inc.php';
require WEBFILEPATH.'/include/email.class.php';

global_CheckPost(
	array(
		array('email','email','',$weblang['api_userEmailError'],1),
));

$webglobal['datainfo'] = $db->GetOne("SELECT * FROM user WHERE email='{$webglobal['CPP']['email']}'");
if (empty($webglobal['datainfo']))
{
	$return['code'] = 1;
	$return['msg'] = $weblang['api_userEmailError'];
	api_EchoReturn();
}
//发送找回密码邮件
//$tempactiveurl = "http://{$webserver['webhost']}".WEBURLPATH."/findpass.php?code=".global_EncryptKey("{$webglobal['datainfo']['uid']},".substr($webglobal['datainfo']['password'],$webglobal['datainfo']['uid']%9,9).",{$webserver['timestamp']}");
$tempnewpassword = strtolower(substr($webglobal['datainfo']['password'],$webglobal['datainfo']['uid']%9,6));
$tempimageurl = "http://{$webserver['webhost']}".WEBURLPATH.'/images/';
$tempmailcontent = <<<EOT
	<table width="600" border="0" cellspacing="0" cellpadding="0" style=" background-color:#FAFAF2;">
	  <tr>
		<td><img src="{$tempimageurl}header.png" /></td>
	  </tr>
	  <tr>
		<td style="padding:10px; font-family:Arial, Helvetica, sans-serif">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td><span style="font-size:22px; line-height:30px; padding:8px;">Hello there:</span></td>
		  </tr>
		  <tr>
			<td height="40" style="border-bottom:#ccc solid 1px; padding:8px;">Please see below for your login information for PrincessWedding</td>
		  </tr>
		  <tr>
			<td height="40" style="border-top:#fff solid 1px; border-bottom:#ccc solid 1px; line-height:30px; padding:8px;">
			Login email is: {$webglobal['CPP']['email']}<br />
			Login password: {$tempnewpassword}
			</td>
		  </tr>
		  <tr>
			<td style="font-size:22px; border-top:#fff solid 1px; line-height:30px; padding:15px 8px 0px 8px;">Support Team</td>
		  </tr>
		  <tr>
			<td style=" line-height:30px; padding:8px;"><span style="float:right">call:1300 FREE2U (1300 3733 28)</span>
			  <a href="http://www.princesswedding.com/" style="color:#F74D7F; text-decoration:none;">www.princesswedding.com</a></td>
		  </tr>
		</table></td>
	  </tr>
	</table>
EOT;
$sendemailobj = new Email();
$sendemailobj->Send($webglobal['CPP']['email'], 'Princess Wedding', $tempmailcontent, 1);

if (!empty($sendemailobj->errorMsg))
{
	$return['code'] = -1;
	$return['msg'] = $weblang['api_databaseError'];
	api_EchoReturn();
}

//$db->Update('user', "password='".md5($tempnewpassword)."',edittime='{$webserver['timestamp']}'", "uid='{$webglobal['datainfo']['uid']}'");
$return['code'] = 0;
api_EchoReturn();
